﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.bandits {
    import Engine.Classes.*;
    import Engine.Managers.*;
    import flash.geom.*;
    import Classes.*;
    import Engine.*;
    import Modules.stats.types.*;

    public class BanditUtil {

        public static function getPoliceStationClosestToScreenCenter():Municipal{
            var _local4:Municipal;
            var _local5:Point;
            var _local6:Number;
            var _local1:Array = Global.world.getObjectsByPredicate(BanditUtil.isPolice);
            if (_local1.length == 0){
                return (null);
            };
            var _local2:Point = new Point((Global.stage.stageWidth / 2), (Global.stage.stageHeight / 2));
            var _local3:Array = [];
            for each (_local4 in _local1) {
                _local5 = IsoMath.tilePosToPixelPos(_local4.getPosition().x, _local4.getPosition().y);
                _local5 = IsoMath.viewportToStage(_local5);
                _local6 = _local5.subtract(_local2).length;
                _local3.push({
                    distance:_local6,
                    station:_local4
                });
            };
            _local3.sortOn("distance", Array.NUMERIC);
            return (_local3[0].station);
        }
        public static function getPoliceStations():Array{
            return (Global.world.getObjectsByPredicate(BanditUtil.isPolice));
        }
        public static function getPoliceStationLevel():int{
            var _local3:Municipal;
            var _local4:int;
            var _local1:Array = getPoliceStations();
            var _local2:int;
            for each (_local3 in _local1) {
                _local4 = Global.gameSettings.getPoliceStationLevel(_local3.getItem().name);
                if (_local4 > _local2){
                    _local2 = _local4;
                };
            };
            return (_local2);
        }
        public static function getPoliceStationInstanceLevel(_arg1:Municipal):int{
            return (Global.gameSettings.getPoliceStationLevel(_arg1.getItem().name));
        }
        public static function isPolice(_arg1:WorldObject):Boolean{
            var _local2:Item;
            if ((_arg1 is MapResource)){
                _local2 = (_arg1 as MapResource).getItem();
                return (((((!((_local2 == null))) && ((_local2.type == "municipal")))) && ((_local2.behavior == "police"))));
            };
            return (false);
        }
        public static function refreshPoliceStationAppearance():void{
            var _local2:Municipal;
            var _local1:Array = Global.world.getObjectsByPredicate(BanditUtil.isPolice);
            for each (_local2 in _local1) {
                _local2.updateStagePickEffect();
            };
        }
        public static function logDialogStats(_arg1:String, _arg2:String, _arg3:BanditData=null, _arg4:int=1):void{
            var _local5:String = ((_arg3)==null) ? null : String(_arg3.id);
            StatsManager.sample(100, StatsCounterType.DIALOG, "active_building", _arg1, "police", _arg2, _local5, _arg4);
        }
        public static function logGameActionStats(_arg1:String, _arg2:String, _arg3:String, _arg4:BanditData=null):void{
            var _local5:String = ((_arg4)==null) ? null : String(_arg4.id);
            StatsManager.sample(100, StatsCounterType.GAME_ACTIONS, _arg1, _arg2, _arg3, _local5);
        }

    }
}//package Modules.bandits 
